package com.szt.mobile.inventory.common.entity;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "t_assetslist".
*/
public class AssetsListDao extends AbstractDao<AssetsList, Long> {

    public static final String TABLENAME = "t_assetslist";

    /**
     * Properties of entity AssetsList.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property _id = new Property(0, Long.class, "_id", true, "_id");
        public final static Property InventoryId = new Property(1, Long.class, "inventoryId", false, "INVENTORY_ID");
    }

    private DaoSession daoSession;

    private Query<AssetsList> inventory_DetailQuery;

    public AssetsListDao(DaoConfig config) {
        super(config);
    }
    
    public AssetsListDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"t_assetslist\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: _id
                "\"INVENTORY_ID\" INTEGER);"); // 1: inventoryId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"t_assetslist\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, AssetsList entity) {
        stmt.clearBindings();
 
        Long _id = entity.get_id();
        if (_id != null) {
            stmt.bindLong(1, _id);
        }
 
        Long inventoryId = entity.getInventoryId();
        if (inventoryId != null) {
            stmt.bindLong(2, inventoryId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, AssetsList entity) {
        stmt.clearBindings();
 
        Long _id = entity.get_id();
        if (_id != null) {
            stmt.bindLong(1, _id);
        }
 
        Long inventoryId = entity.getInventoryId();
        if (inventoryId != null) {
            stmt.bindLong(2, inventoryId);
        }
    }

    @Override
    protected final void attachEntity(AssetsList entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public AssetsList readEntity(Cursor cursor, int offset) {
        AssetsList entity = new AssetsList( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // _id
            cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1) // inventoryId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, AssetsList entity, int offset) {
        entity.set_id(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setInventoryId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(AssetsList entity, long rowId) {
        entity.set_id(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(AssetsList entity) {
        if(entity != null) {
            return entity.get_id();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(AssetsList entity) {
        return entity.get_id() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "detail" to-many relationship of Inventory. */
    public List<AssetsList> _queryInventory_Detail(Long inventoryId) {
        synchronized (this) {
            if (inventory_DetailQuery == null) {
                QueryBuilder<AssetsList> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.InventoryId.eq(null));
                inventory_DetailQuery = queryBuilder.build();
            }
        }
        Query<AssetsList> query = inventory_DetailQuery.forCurrentThread();
        query.setParameter(0, inventoryId);
        return query.list();
    }

}
